/**
 * @file Describe the file Created by Administrator on 2015/5/20.
 */
function MaskUtil() {

    var enMsgBoxId = ''; // 重要
    // 弹出对话窗口(msgID-要显示的div的id)
    this.evModeAlert = function (msgID) {
        // 创建大大的背景框
        var bgObj = document.createElement('div');
        bgObj.setAttribute('id', 'EV_bgModeAlertDiv');
        document.body.appendChild(bgObj);
        // 背景框满窗口显示
        evShowBgDiv();
        // 把要显示的div居中显示
        enMsgBoxId = msgID;
        evShowMsgDiv();
    };

    // 关闭对话窗口
    this.evCloseAlert = function () {
        var msgObj = document.getElementById(enMsgBoxId);
        var bgObj = document.getElementById('EV_bgModeAlertDiv');
        msgObj.style.display = 'none';
        document.body.removeChild(bgObj);
        enMsgBoxId = '';
    };

    // 窗口大小改变时更正显示大小和位置
    window.onresize = function () {
        if (enMsgBoxId.length > 0) {
            evShowBgDiv();
            evShowMsgDiv();
        }
    };

    // 窗口滚动条拖动时更正显示大小和位置
    window.onscroll = function () {
        if (enMsgBoxId.length > 0) {
            evShowBgDiv();
            evShowMsgDiv();
        }
    };

    // 把要显示的div居中显示
    function evShowMsgDiv() {
        var msgObj = document.getElementById(enMsgBoxId);
        msgObj.style.display = 'block';
        var msgWidth = msgObj.scrollWidth;
        var msgHeight = msgObj.scrollHeight;
        var bgTop = evMyScrollTop();
        var bgLeft = evMyScrollLeft();
        var bgWidth = evMyClientWidth();
        var bgHeight = evMyClientHeight();
        var msgTop = bgTop + Math.round((bgHeight - msgHeight) / 2);
        var msgLeft = bgLeft + Math.round((bgWidth - msgWidth) / 2);
        msgObj.style.position = 'absolute';
        msgObj.style.top = msgTop + 'px';
        msgObj.style.left = msgLeft + 'px';
        msgObj.style.zIndex = '10001';

    }
    // 背景框满窗口显示
    function evShowBgDiv() {
        var bgObj = document.getElementById('EV_bgModeAlertDiv');
        var bgWidth = evMyClientWidth();
        var bgHeight = evMyClientHeight();
        var bgTop = evMyScrollTop();
        var bgLeft = evMyScrollLeft();
        bgObj.style.position = 'absolute';
        bgObj.style.top = bgTop + 'px';
        bgObj.style.left = bgLeft + 'px';
        bgObj.style.width = bgWidth + 'px';
        bgObj.style.height = bgHeight + 'px';
        bgObj.style.zIndex = '10000';
        bgObj.style.background = '#777';
        bgObj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60,finishOpacity=60);';
        bgObj.style.opacity = '0.6';
    }
    // 网页被卷去的上高度
    function evMyScrollTop() {
        var n = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
        return n;
    }
    // 网页被卷去的左宽度
    function evMyScrollLeft() {
        var n = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
        return n;
    }
    // 网页可见区域宽
    function evMyClientWidth() {
        var n = document.documentElement.clientWidth || document.body.clientWidth || 0;
        return n;
    }
    // 网页可见区域高
    function evMyClientHeight() {
        var n = document.documentElement.clientHeight || document.body.clientHeight || 0;
        return n;
    }
}